
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include"list.h"

using namespace std;


void test1()
{
    mylist::list<int> lt;
    lt.push_back(1);
    lt.push_back(2);
    lt.push_back(3);
    lt.push_back(4);
    lt.push_back(5);

    mylist::list<int>::iterator it = lt.begin();
    while (it != lt.end())
    {
        cout << *it << " ";
        ++it;
    }
    cout << endl;
}

int triangleNumber(vector<int>& nums)
{
    sort(nums.begin(), nums.end());
    int count = 0;
    for (int i = nums.size() - 1; i >= 2; i--)
    {
        int left = 0, right = i - 1;
        int key = i;
        while (left < right)
        {
            int sum = nums[left] + nums[right];
            if ( sum > nums[key])
            {
                count += (right - left);
                right--;
            }
            else
            {
                left++;
            }
        }
    }
    return count;
}





int main()
{
    vector<int> v;
    v.push_back(2);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);

    int ret = triangleNumber(v);

	return 0;
}